import request from "@/utils/request.ts";
import { Result } from "@/types/types.ts";

enum API {
  // 获取首页医院分页列表
  HOSPITAL_LIST = "/hosp/hospital/",
  // 获取医院的等级与地区字典的接口
  FIND_BY_DICT_CODE = "/cmn/dict/findByDictCode/",
  // GET /api/hosp/hospital/findByHosname/{hosname}
  // 根据医院名称获取医院列表
  FIND_BY_HOSPITAL_NAME = "/hosp/hospital/findByHosname/",
}
// 获取首页医院分页列表
export const doGetHospitalList = (
  page: number = 1,
  limit: number = 5,
  hostype?: string,
  districtCode?: string,
  hosname?: string,
  hoscode?: string,
  provinceCode?: string,
  cityCode?: string,
  status?: number,
) => {
  return request<any, Result>({
    url: API.HOSPITAL_LIST + `${page}/${limit}`,
    method: "get",
    params: {
      hostype,
      districtCode,
      hosname,
      hoscode,
      provinceCode,
      cityCode,
      status,
    },
  })
    .then((res) => {
      return res;
    })
    .catch((err) => {
      return err;
    });
};

// 根据字典编码获取字典数据
export const doFindByDictCode = (dictCode: string) => {
  return request<any, Result>({
    url: API.FIND_BY_DICT_CODE + `${dictCode}`,
  })
    .then((res) => {
      return res;
    })
    .catch((err) => {
      return err;
    });
};
// 根据医院名称获取医院列表
export const doFindByHospitalName = (hosname: string) => {
  return request<any, Result>({
    url: API.FIND_BY_HOSPITAL_NAME + `${hosname}`,
  })
    .then((res) => {
      return res;
    })
    .catch((err) => {
      return err;
    });
};
